<?php
namespace app\index\controller;
use think\Controller;
use think\Db;
use think\Request;
use think\Loader;

class GaodeAvoid extends Controller
{
    public function getGaodeavoid()
    {
        error_reporting(E_ALL ^ E_NOTICE);
        $data=file_get_contents("php://input"); 
        $mydata=json_decode($data);
        $start=$mydata->start;
        $end=$mydata->end;
        $avoidPoint=$mydata->avoidPoint;
        $avoidRoad=$mydata->avoidRoad;
        // $end=$_POST['end'];
        // $avoidPoint=$_POST['avoidPoint'];
        // echo $start;
        $url='http://restapi.amap.com/v3/direction/driving?key=6369dc95d043e66b1a3ca2f409cc2557&origin='.$start.'&destination='.$end.'&originid=&destinationid=&extensions=base&strategy=距离最短&waypoints=&avoidpolygons='.$avoidPoint.'&avoidroad='.$avoidRoad;
        //  var_dump($url);
        $curl = curl_init();
        //设置抓取的url
        curl_setopt($curl, CURLOPT_URL,$url);
        //设置头文件的信息作为数据流输出
        curl_setopt($curl, CURLOPT_HEADER, 1);
        //设置获取的信息以文件流的形式返回，而不是直接输出。
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        //执行命令
        $response = curl_exec($curl);
        //关闭URL请求
        curl_close($curl);
        $obj = json_decode($response); //可以使用$obj->name访问对象的属性
        //显示获得的数据
        $needle='{';
        $m=strpos ($response,$needle,0);
        $response_json=substr($response,$m ,strlen($response));
        //$response_json=json_decode($response_json);
        echo $response_json;
    }   
}
